package com.wxm.proxy;

import org.springframework.cglib.proxy.InvocationHandler;
import org.springframework.cglib.proxy.Proxy;

import java.lang.reflect.Method;

public class OrderServiceProxy implements InvocationHandler {
    private Object target;

    public Object getInstance(Object target){
        this.target = target;
        Class clazz = target.getClass();
        return Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this);
    }
    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        System.out.println("before");
        System.out.println(objects[0]);
        System.out.println(target);
        Object order = objects[0];
        System.out.println(order.getClass());
        System.out.println(order.getClass().getMethod("getCreateTime").invoke(order));
        Object obj =method.invoke(target,objects);
        System.out.println("after");
        return obj;
    }
}
